package com.liuhung.base.util;
import java.io.IOException;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
 * 重新定制json的样式
 * @ClassName: ObjectMappingCustomer 
 * @Description: TODO(这里用一句话描述这个类的作用) 
 * @author 刘  鸿 
 * @date 2015-5-21 下午10:51:30
 */
public class ObjectMappingCustomer extends ObjectMapper
{

    /************************************************	
	 * @Fields serialVersionUID : TODO
	 ***********************************************/
	private static final long serialVersionUID = -671873340898360675L;

	public ObjectMappingCustomer()
    {
        super();
        /**
        // 允许单引号
        this.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
        // 字段和值都加引号
        this.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
        // 数字也加引号
        this.configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, true);
        this.configure(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS, true);
        // 空值处理为空串
         * 
         */
        this.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>()
        {
			@Override
			public void serialize(Object arg0, JsonGenerator jg, SerializerProvider arg2)
					throws IOException, JsonProcessingException {
				 jg.writeString("");
			}
        });

    }
}
